/**
 * 
 */
package com.base.myproject.client.system;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.extjs.gxt.ui.client.data.ModelType;

/**
 * 将常用的数据放入到缓冲区里
 * 
 * @author zgw 2009-10-29 下午01:35:14 javazgw@gmail.com
 */
public class StoreCache {
	static StoreCache storecache;

	static BaseStore<BusiObject> ccodestore;
	static BaseStore<BusiObject> bcodestore;
	private StoreCache() {

	}

	public static StoreCache getInstance() {
		if (storecache == null) {
			storecache = new StoreCache();
		}
		return storecache;
	}

	/**
	 * 客户 
	 * filter 格式 where 1=1
	 * @return the ccodestore
	 */
	public static BaseStore<BusiObject> getCcodestore(String filter) {
		
		if(ccodestore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("icode");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("ccode");
			if(filter!=null)
			{
				info.setSql("select ccode as code,cname as name from ccode where " + filter);
			}
			else
			{
				info.setSql("select ccode as code,cname as name from ccode ");
			}
			info.setKeyname(new String[] { "icode" });
			info.setNeedAllRow("no");
			ccodestore = new BaseStore<BusiObject>(type,info);
		}
		return ccodestore;
	}

	/**
	 * @param ccodestore the ccodestore to set
	 */
	public static void setCcodestore(BaseStore<BusiObject> ccodestore) {
		StoreCache.ccodestore = ccodestore;
	}

	/**
	 * 部门
	 * @return the bcodestore
	 */
	public static BaseStore<BusiObject> getBcodestore(String filter) {
		
		if(bcodestore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("icode");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("ccode");
			if(filter!=null)
			{
				info.setSql("select bcode as code,bname as name from bcode where " + filter);
			}
			else
			{
				info.setSql("select bcode as code,bname as name from bcode ");
			}
			
			info.setNeedAllRow("no");
			bcodestore = new BaseStore<BusiObject>(type,info);
		}
		
		return bcodestore;
	}

	/**
	 * @param bcodestore the bcodestore to set
	 */
	public static void setBcodestore(BaseStore<BusiObject> bcodestore) {
		StoreCache.bcodestore = bcodestore;
	}
	 
}
